package com.yanfan.data.controller;

import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.data.domain.SnmpResponse;
import com.yanfan.data.service.ISnmpResponseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * snmp响应结果Controller
 *
 * @author kerwincui
 * @date 2024-07-28
 */
@RestController
@RequestMapping("/data/response")
public class SnmpResponseController extends BaseController {
    @Autowired
    private ISnmpResponseService snmpResponseService;

    /**
     * 查询snmp响应结果列表
     */
    //@PreAuthorize("@ss.hasPermi('data:response:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnmpResponse snmpResponse) {
        startPage();
        List<SnmpResponse> list = snmpResponseService.selectSnmpResponseList(snmpResponse);
        return getDataTable(list);
    }

    /**
     * 导出snmp响应结果列表
     */
    //@PreAuthorize("@ss.hasPermi('data:response:export')")
    @Log(title = "snmp响应结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnmpResponse snmpResponse) {
        List<SnmpResponse> list = snmpResponseService.selectSnmpResponseList(snmpResponse);
        ExcelUtil<SnmpResponse> util = new ExcelUtil<SnmpResponse>(SnmpResponse.class);
        util.exportExcel(response, list, "snmp响应结果数据");
    }

    /**
     * 获取snmp响应结果详细信息
     */
    //@PreAuthorize("@ss.hasPermi('data:response:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(snmpResponseService.selectSnmpResponseById(id));
    }

    /**
     * 新增snmp响应结果
     */
    //@PreAuthorize("@ss.hasPermi('data:response:add')")
    @Log(title = "snmp响应结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnmpResponse snmpResponse) {
        return toAjax(snmpResponseService.insertSnmpResponse(snmpResponse));
    }

    /**
     * 修改snmp响应结果
     */
    //@PreAuthorize("@ss.hasPermi('data:response:edit')")
    @Log(title = "snmp响应结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnmpResponse snmpResponse) {
        return toAjax(snmpResponseService.updateSnmpResponse(snmpResponse));
    }

    /**
     * 删除snmp响应结果
     */
    //@PreAuthorize("@ss.hasPermi('data:response:remove')")
    @Log(title = "snmp响应结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(snmpResponseService.deleteSnmpResponseByIds(ids));
    }
}
